package io.finer.erp.jeecg.jolimark.comm;

import io.finer.erp.jeecg.jolimark.print.CreateAccessToken;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class Config {

	@Value(value = "${jolimark.url.v3}")
	private String urlV3;
	@Value(value = "${jolimark.url.v2}")
	private String urlV2;
	@Value(value = "${jolimark.app_id}")
	private String appid;
	@Value(value = "${jolimark.app_key}")
	private String appKey;
	@Value(value = "${jolimark.printer.CFP535}")
	private String printDevice;

	private static String URLV3;

	private static String URLV2;

	private static String APPID;

	private static String APPKEY;

	private static String PRINTDEVICE;

	private static String ACCESSTOKEN;

	@PostConstruct
	public void getApiToken() {
		URLV3 = this.urlV3;
		URLV2 = this.urlV2;
		APPID = this.appid;
		APPKEY = this.appKey;
		PRINTDEVICE = this.printDevice;
		ACCESSTOKEN = this.getAccessToken();
	}

	public static String getUrlV3() {
		return URLV3;
	}

	public static String getUrlV2() {
		return URLV2;
	}

	public static String getAppID() {
		return APPID;
	}

	public static String getAppKey() {
		return APPKEY;
	}

	public static String getAccessToken() {
		if(StringUtils.isBlank(ACCESSTOKEN)){
			CreateAccessToken createAccessToken = new CreateAccessToken();
			createAccessToken.accessToken();
		}
		return ACCESSTOKEN;
	}

	public static void setAccessToken(String accessToken) {
		ACCESSTOKEN = accessToken;
	}

	public static String getPrintDevice(){
		return PRINTDEVICE;
	}
}
